
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include "ReqPipe.mqh"

class SimpleTrader
{
public:
	SimpleTrader();
	~SimpleTrader();

	void Init(string symbol, int magicCode, double losts = 0.1);
	void Buy();
	void Sell();
	void Close();
protected:

private:
	string   symbol;
	int		MagicCode;
	double 	losts;
	double            m_adjusted_point;             // point value adjusted for 3 or 5 points
	CTrade            m_trade;                      // trading object
	CSymbolInfo       m_symbol;                     // symbol info object
	CPositionInfo     m_position;                   // trade position object
	CAccountInfo      m_account;                    // account info wrapper
	double InpLots; // Lots
	int    InpTakeProfit;  // Take Profit (in pips)
	int    InpTrailingStop;  // Trailing Stop Level (in pips)
	double            m_traling_stop;
	double            m_take_profit;

	bool Update();
	void PositionOpenBuy();
	void PositionOpenSell();
	void PositionClose();


	
};


class RateDataCollector
{
public:
	RateDataCollector();
	~RateDataCollector();

	void Init(string symbol, ENUM_TIMEFRAMES  timeframe);
	void GetRateData(int count, MqlRates &rates[], int &count_out);
   void RateDataCollector::GetByTime(MqlRates &rates[], int &count_out, datetime start, datetime end);

private:
	string m_symbolName;
   CSymbolInfo       m_symbol;                     // symbol info object
	ENUM_TIMEFRAMES m_timeFrame;
	int m_skipNum;
	
};



class RemoteTrader
{
public:
	RemoteTrader();
	~RemoteTrader();

	void Init(string symbol, ENUM_TIMEFRAMES timeframe, SimpleTrader &trader);
	void Process();
	void Close();

private:
	string _symbol;
	ENUM_TIMEFRAMES _timeframe;
	SimpleTrader _trader;
	ReqPipe _pipe;
	GetActionReq _getActionReq;
	RateDataCollector _collector;
	datetime _last_itme_time;
	datetime _last_check_time;
	datetime _update_interve;


	bool CheckUpdate();
	MqlRates GetRates(int count);
	
};